layui.use(['table','layer','form','laytpl'], function(){
	let layer = layui.layer, form = layui.form, laytpl = layui.laytpl, $ = layui.$;

	/*@数据渲染*/
	$(function(){
		console.log(parent.layui.purchase)
		$('input[name="goods_name"]').val(parent.layui.purchase.goods_name)
		$('input[name="category_name"]').val(parent.layui.purchase.category_name)
		$('input[name="cat_name"]').val(parent.layui.purchase.cate_name)
		$('input[name="brand_name"]').val(parent.layui.purchase.brand_name)
		$('input[name="memory_name"]').val(parent.layui.purchase.memory_name)
		$('input[name="marker"]').val(parent.layui.purchase.marker)
		$('input[name="attribute_name"]').val(parent.layui.purchase.attribute_name)
		$('input[name="colour_name"]').val(parent.layui.purchase.colour_name)
		$('input[name="unit"]').val(parent.layui.purchase.unit)
	})
	/*@总价*/
	ptotal = function(obj, other_field, total_field){
		let v = $(obj).val()
		let other_v = $('input[name="'+other_field+'"]').val()
		let total_v = Number(v*100) * Number(other_v*100) / 10000;
		$('input[name="'+total_field+'"]').val(total_v)
	}
	/*@提交*/
	form.on('submit(add)', function(data){
		$.post(window.location.pathname, data.field, function(msg){
			if(msg.code !== 1){
				layer.msg(msg.msg, {icon: 5})
			}else{
				layer.msg(msg.msg, {icon: 6, time: 1000}, function(){
					xadmin.close()
				})
			}
		})
	})
})